/**
 * Validate v1.0.0 通用验证
 * @description 项目中用到的表单验证规则
 */
import test from '@/sheep/helper/test.js';
import i18n from '@/sheep/i18n-lang'

const { t } = i18n.global
// 手机号
export const mobile = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.mobile'),
    },
    // {
    //   validateFunction: function (rule, value, data, callback) {
    //     if (!test.mobile(value)) {
    //       callback(t('validate.mobileVa'));
    //     }
    //     return true;
    //   },
    // },
  ],
};


// 邮箱
export const email = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.email'),
    },
    {
      validateFunction: function (rule, value, data, callback) {
        if (!test.email(value)) {
          callback(t('validate.emailVa'));
        }
        return true;
      },
    },
  ],
};

// 账户
export const account = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.account'),
    },
    {
      validateFunction: function (rule, value, data, callback) {
        if (value.length < 5) {
          // callback(t('validate.accountVa'));
        }
        return true;
      },
    },
  ],
};

// 密码
export const password = {
  rules: [
    {
      required: true,
      errorMessage: '请输入密码',
    },
    {
      validateFunction: function (rule, value, data, callback) {
        // if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]+\S{5,12}$/.test(value)) {
        if (!/^[A-Za-z0-9]{6,12}$/.test(value)) {
          callback('密码长度在6-12之间');
        }
        return true;
      },
    },
  ],
};

// 昵称
export const username = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.username'),
    },
    {
      validateFunction: function (rule, value, data, callback) {
        if (value.length < 5) {
          callback(t('validate.usernameVa'));
        }
        return true;
      },
    },
  ],
};

// 短信验证码
export const code = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.code'),
    },
  ],
};

// 真实姓名
export const realName = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.realName'),
    },
    {
      validateFunction: function (rule, value, data, callback) {
        if (!test.chinese(value)) {
          callback(t('validate.realNameVa'));
        }
        return true;
      },
    },
  ],
};

// usdt_url
export const usdt_url = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.usdt_url'),
    },
    // {
    //   validateFunction: function (rule, value, data, callback) {
    //     if (!test.url(value)) {
    //       callback('请输入usdt链接');
    //     }
    //     return true;
    //   },
    // },
  ],
};

export const taxName = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.taxName'),
    },
    {
      validateFunction: function (rule, value, data, callback) {
        if (!test.chinese(value)) {
          callback(t('validate.taxNameVa'));
        }
        return true;
      },
    },
  ],
};

// 税号
export const taxNo = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.taxNo'),
    },
  ],
};

// 开户行
export const bankName = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.bankName'),
    },
    {
      validateFunction: function (rule, value, data, callback) {
        if (!test.chinese(value)) {
          callback(t('validate.bankNameVa'));
        }
        return true;
      },
    },
  ],
};
// 银行卡号
export const bankCode = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.bankCode'),
    },
    {
      validateFunction: function (rule, value, data, callback) {
        if (!test.number(value)) {
          callback(t('validate.bankCodeVa'));
        }
        return true;
      },
    },
  ],
};

// 支付宝账号
export const alipayAccount = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.alipayAccount'),
    },
    {
      validateFunction: function (rule, value, data, callback) {
        let isEmail = test.email(value);
        let isMobile = test.mobile(value);

        if (!isEmail && !isMobile) {
          callback(t('validate.alipayAccountVa'));
        }
        return true;
      },
    },
  ],
};

export const consignee = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.consignee'),
    },
  ],
};

export const region = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.region'),
    },
  ],
};
export const address = {
  rules: [
    {
      required: true,
      errorMessage: t('validate.address'),
    },
  ],
};

export default {
  mobile,
  alipayAccount,
  bankCode,
  bankName,
  realName,
  password,
  code,
  account,
  consignee,
  address,
  region,
  taxNo,
  taxName,
};
